<?php
include('includes/connexion.php');

$elevemanager = new EleveManager($connexion);
$adminmanager = new AdminManager($connexion);
session_start();

include('includes/secu.php');

$classemanager = new ClasseManager($connexion);
$collegemanager = new CollegeManager($connexion);
$resultatmanager = new ResultatManager($connexion);

$testmanager = new TestManager($connexion);
$exercicemanager = new ExerciceManager($connexion);
$questionmanager = new QuestionManager($connexion);
$reponsemanager = new ReponseManager($connexion);
$test_exercicemanager = new Test_ExerciceManager($connexion);

if(isset($_GET['init']))
{
	$resultatmanager->reinitializeExercice($_GET['eleve'], $_GET['ex'], $_GET['test']);
	header('Location: resultats.php');
}
?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
  <title>Tables Advanced - Target Admin</title>

  <meta charset="utf-8">
  <meta name="description" content="">
  <meta name="viewport" content="width=device-width">

  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,700italic,400,600,700">
  <link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Oswald:400,300,700">
  <link rel="stylesheet" href="./css/font-awesome.min.css">
  <link rel="stylesheet" href="./js/libs/css/ui-lightness/jquery-ui-1.9.2.custom.min.css">
  <link rel="stylesheet" href="./css/bootstrap.min.css">

  <!-- Plugin CSS -->
  <link rel="stylesheet" href="./js/plugins/icheck/skins/minimal/blue.css">
  <link rel="stylesheet" href="js/plugins/select2/select2.css">
  <link rel="stylesheet" href="js/plugins/datepicker/datepicker.css">
  <link rel="stylesheet" href="js/plugins/simplecolorpicker/jquery.simplecolorpicker.css">
  <link rel="stylesheet" href="js/plugins/timepicker/bootstrap-timepicker.css">
  <link rel="stylesheet" href="js/plugins/fileupload/bootstrap-fileupload.css">
  
  <!-- App CSS -->
  <link rel="stylesheet" href="./css/target-admin.css">
  <link rel="stylesheet" href="./css/custom.css">


  <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
  <!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
  <![endif]-->
</head>

<body>

<?php include('includes/navbar.php'); ?>

<?php include('includes/mainbar.php'); ?>

<div class="container">

  <div class="content">

    <div class="content-container">

      

      <div class="content-header">
        <h2 class="content-header-title">Résultats</h2>
      </div> <!-- /.content-header --> 

      <div class="row">

        <div class="col-md-12">

          <div class="portlet">

            <div class="portlet-header">

              <h3>
                <i class="fa fa-table"></i>
                Liste des résultats
              </h3>

            </div> <!-- /.portlet-header -->

            <div class="portlet-content">           

              <div class="table-responsive">

              <table 
                class="table table-striped table-bordered table-hover table-highlight table-checkable" 
                data-provide="datatable" 
                data-display-rows="10"
                data-info="true"
                data-search="true"
                data-length-change="true"
                data-paginate="true"
              >
                  <thead>
                    <tr>
                      <th>Option</th>
                      <th data-filterable="true" data-sortable="true" data-direction="desc">Nom</th>
                      <th data-filterable="true" data-sortable="true">Prénom</th>
                      <th data-filterable="true" data-sortable="true">Date de naissance</th>
                      <th data-filterable="true" data-sortable="true">Classe</th>
                      <th data-filterable="true" data-sortable="true">Test</th>
                      <th>Etat</th>
                    </tr>
                  </thead>
                  <tbody>
<?php foreach($resultatmanager->getListEleve() as $key => $value){
	$valueX = $value;
	$value = $elevemanager->get($value->idRefEleve());
    if( $_SESSION['Admin']->idRefCollege() != NULL && $classemanager->get($value->idRefClasse())->idRefCollege() != $_SESSION['Admin']->idRefCollege() ){
		continue;
	}
?>
                    <tr>
                      <td>
                      <?php foreach($test_exercicemanager->getByTest($valueX->idRefTest()) as $testex)
					  {
							if($resultatmanager->getByExerciceEleveTest($testex->idRefExercice(), $value->id(),$valueX->idRefTest()) != NULL)
							{
								echo "<a href='?init=1&ex=".$testex->idRefExercice()."&eleve=".$value->id()."&test=".$valueX->idRefTest()."'>Réinitialiser ".$exercicemanager->get($testex->idRefExercice())->intitule()."</a>";
							}
							echo "<br>";  
					  } ?>
                      </td>
                      <td><?php echo $value->nom();?></td>
                      <td><?php echo $value->prenom();?></td>
                      <td><?php echo date("d/m/Y", $value->datenaissance());?></td>
                      <td><?php echo $collegemanager->get($classemanager->get($value->idRefClasse())->idRefCollege())->nom()." - ".$classemanager->get($value->idRefClasse())->nom();?></td>
                      <td><?php echo $testmanager->get($valueX->idRefTest())->intitule()." (".$testmanager->get($valueX->idRefTest())->duree()." heure(s))"; ?></td>
                      <td align="center">
                      <?php
					  $x = 0;
					  $y = 0;
					  foreach($test_exercicemanager->getByTest($valueX->idRefTest()) as $testex)
					  {
						  if($exercicemanager->get($testex->idRefExercice())->type() != "IP" && $exercicemanager->get($testex->idRefExercice())->type() != "Q"){
						  	$x++;
							if($resultatmanager->getByExerciceEleveTest($testex->idRefExercice(), $value->id(),$valueX->idRefTest()) != NULL)
							{
								echo "<font color='#00FF00'>".$exercicemanager->get($testex->idRefExercice())->intitule()."</font>";
								$y++;
							} else {
								echo "<font color='#FF0000'>".$exercicemanager->get($testex->idRefExercice())->intitule()."</font>";
							}
							echo "<br>"; 
						  }
					  }
					  if($x == $y)
					  {
						echo '<a href="impr_rapport_eleve.php?id='.$valueX->id().'"><button type="button" class="btn btn-danger">Rapport Individuel</button></a><br>';
						echo '<a href="impr_rapport_classe.php?id='.$value->idRefClasse().'"><button type="button" class="btn btn-danger">Rapport Classe</button></a><br>';
					  }
					  ?>
                      
                      </td>
                    </tr>
<?php } ?>
                  </tbody>
                </table>
              </div> <!-- /.table-responsive -->

            </div> <!-- /.portlet-content -->

          </div> <!-- /.portlet -->

        </div> <!-- /.col -->

      </div> <!-- /.row -->

    </div> <!-- /.content-container -->
      
  </div> <!-- /.content -->

</div> <!-- /.container -->


<?php include('includes/footer.php'); ?>

  <script src="./js/libs/jquery-1.10.1.min.js"></script>
  <script src="./js/libs/jquery-ui-1.9.2.custom.min.js"></script>
  <script src="./js/libs/bootstrap.min.js"></script>

  <!--[if lt IE 9]>
  <script src="./js/libs/excanvas.compiled.js"></script>
  <![endif]-->
  
  <!-- Plugin JS -->
  <script src="./js/plugins/datatables/jquery.dataTables.min.js"></script>
  <script src="./js/plugins/datatables/DT_bootstrap.js"></script>
  <script src="./js/plugins/tableCheckable/jquery.tableCheckable.js"></script>
  <script src="./js/plugins/icheck/jquery.icheck.min.js"></script>

  <!-- App JS -->
  <script src="./js/target-admin.js"></script>
  


  
</body>
</html>